package com.itheima.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

public class SqlSessionUtils {
    // 加载一次核心配置文件
    private static SqlSessionFactory factory;

    static {

        try {
            InputStream in = Resources.getResourceAsStream("SqlMapperConfig.xml");
            factory = new SqlSessionFactoryBuilder().build(in);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    /*
        获取sqlSession对象
     */
    public static SqlSession getSqlSession() {
        return factory.openSession();
    }



}
